#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
int main(){
    int n;
    cin>>n;
    int suma=0,sume=0,sumc=0;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        suma+=a;
        int e;
        cin>>e;
        sume+=e;
        int c;
        cin>>c;
        if(c==0)sumc+=1;
    }
    int res_a=n*8-suma;
    int res_e=n*12-sume;
    int res_c=sumc;
    int minn=min(res_a/8,res_e/12);
    minn=min(minn,res_c);
    cout<<minn<<endl;
 
    return 0;
}